package com.yf.exam.modules.exam.dto.response;

import com.yf.exam.enums.ExamState;
import com.yf.exam.modules.exam.dto.ExamDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* <p>
* 考试分页响应类
* </p>
*
* @author 聪明笨狗
* @since 2020-07-25 16:18
*/
@Data
@ApiModel(value="在线考试分页响应类", description="在线考试分页响应类")
public class ExamOnlineRespDTO extends ExamDTO {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "我的考试次数", required=true)
    private Integer tryCount;



    /**
     * 是否结束
     * @return
     */
    @Override
    public Integer getState(){

        // 考试问题
        if(getChance()!=null
            && super.getChance() > 0
            && tryCount!=null
            && tryCount>=super.getChance()){
            return ExamState.OVERDUE;
        }

        if(System.currentTimeMillis() < getStartTime().getTime() ){
            return ExamState.READY_START;
        }

        if(System.currentTimeMillis() > getEndTime().getTime()){
            return ExamState.OVERDUE;
        }

        if(System.currentTimeMillis() > getStartTime().getTime()
                && System.currentTimeMillis() < getEndTime().getTime()
                && !ExamState.DISABLED.equals(super.getState())){
            return ExamState.ENABLE;
        }



        return super.getState();
    }



}
